package com.mathlearning.auth.dto.problem;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CreateProblemRequest {
    @NotNull(message = "课程ID不能为空")
    private Long courseId;
    private Long chapterId;
    @NotBlank(message = "题目标题不能为空")
    private String title;
    @NotBlank(message = "题目类型不能为空")
    private String type; // choice, fill, calculation
    @NotBlank(message = "题目难度不能为空")
    private String difficulty; // easy, medium, hard
    @NotBlank(message = "题目描述不能为空")
    private String description;
    private String inputDescription;
    private String outputDescription;
    private List<Example> examples;
    private List<String> hints;
    private List<String> tags;
    private List<Option> options; // For choice type
    @NotBlank(message = "正确答案不能为空")
    private String correctAnswer;
    private String solution; // 题解

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Example {
        private String input;
        private String output;
        private String explanation;
    }

    @Data
    @NoArgsConstructor
    public static class Option {
        private String key;
        private String value;
        
        // 全参构造函数
        public Option(String key, String value) {
            this.key = key;
            this.value = value;
        }
        
        // 字符串构造函数以支持Jackson反序列化
        @JsonCreator
        public Option(String value) {
            this.key = value;
            this.value = value;
        }
        
        // Builder模式
        public static OptionBuilder builder() {
            return new OptionBuilder();
        }
        
        public static class OptionBuilder {
            private String key;
            private String value;
            
            public OptionBuilder key(String key) {
                this.key = key;
                return this;
            }
            
            public OptionBuilder value(String value) {
                this.value = value;
                return this;
            }
            
            public Option build() {
                return new Option(key, value);
            }
        }
    }
}



